package custom.cards;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import android.os.AsyncTask;
import android.util.Log;

public class NetworkTask extends AsyncTask<Void, Void, Void> 
{
	private Socket clientSocket;
	private final GameRequest r;
	/*
	 * TODO: you can change this ip to your local server ip to have the app talk to the server,
	 * but only storm and my (Richard's) local PC has access to the google API. So if you want
	 * to have the app work fully you'll have to let me add your home computer's IP to the google server, or just
	 * ask me to run the server on storm for you to use it.
	 * 
	 */
	private final String hostname = "storm.cise.ufl.edu";
	private final int port = 6789;
	
	
	  public NetworkTask(GameRequest req) 
	  {
	    this.r = req;
	  }

	  public void onPreExecute() 
	  {
	    
	  }

	  public Void doInBackground(Void... unused) 
	  {
		  try
			{
			
			    clientSocket = new Socket(hostname, port);

			  
			  	ObjectOutputStream	oo = new ObjectOutputStream(clientSocket.getOutputStream());
				ObjectInputStream	ois = new ObjectInputStream(clientSocket.getInputStream());
				
				oo.writeObject(r);

				oo.close();
				ois.close();
				clientSocket.close();
			}
			catch (Exception e)
			{
				Log.e("Error performing work", e.toString());
				
			}
		 
		  return null;
	  }

	  public void onPostExecute(Void unused) 
	  {
	   
	  }
	  
	  
	  
	  
	}
